$(function(){

	requestPort();//分口
	requestDepartment();//部门
	requestinputping();//录入评价
	requestfinishping();//完成评价
	requestSource();//渠道
	requesFlow();//流程
	requestSort();//分类
	requestClassification();//分级地址


function requestinputping()//录入评价
{
	var url="getAllInformationQuality.do";//分级地址
	var data={};
	var object={};
	data=YuXi.util.get(url,"null",function(data){
		object=data.object;
		//用data循环添加分口信息
		for(var i=0;i<object.length;i++)
		{ 
			var html="<option  value="+object[i].id+" >"+object[i].name+"</option>";
			$(".reinputDian").append(html);
		}
	},function(){
		
	});//请求数据

}
function requestfinishping()//完成评价
{

	var url="getAllTasCompletion.do";//分级地址
	var data={};
	var object={};
	data=YuXi.util.get(url,"null",function(data){
		object=data.object;
		//用data循环添加分口信息
		for(var i=0;i<object.length;i++)
		{
			var html="<option  value="+object[i].id+" >"+object[i].name+"</option>";
			$(".refinishDian").append(html);
		}
	},function(){
		
	});//请求数据
} 

function requesFlow()//流程
{	

	var object=[{id:1,name:"信息管理"},{id:2,name:"初审"},{id:3,name:"复核"},{id:4,name:"审核"},
	{id:5,name:"信息研判"},{id:6,name:"任务派遣"},{id:7,name:"即时任务派遣"},{id:8,name:"任务完成情况"},{id:9,name:"点评"},
	{id:10,name:"评价"},{id:11,name:"结束"}];
	for(var i=0;i<object.length;i++)
	{
		var html= "<option  value="+object[i].id+" >"+object[i].name+"</option>";
		$(".reSearchFlow").append(html);
	}
	object=[{id:2,name:"初审"},{id:3,name:"复核"},{id:4,name:"审核"},
	{id:5,name:"信息研判"},{id:6,name:"任务派遣"},{id:7,name:"即时任务派遣"},{id:8,name:"任务完成情况"},{id:9,name:"点评"},
	{id:10,name:"评价"},{id:11,name:"结束"}];
	$("#specialflow").html('<option value=null selected="selected">流程(所有)</option>');
	for(var i=0;i<object.length;i++)
	{
		var html= "<option  value="+object[i].id+" >"+object[i].name+"</option>";
		$("#specialflow").append(html);
	}
}
//向后台请求分级信息
function requestClassification()
{	
	var url="getAllInformationClassification.do";//分级地址
	var data={};
	var object={};
	data=YuXi.util.get(url,"null",function(data){
		object=data.object;
		//用data循环添加分口信息
		for(var i=0;i<object.length;i++)
		{
			var html="<option  value="+object[i].id+" >"+object[i].name+"</option>";
			$(".pes").append(html);
		}
	},function(){
		
	});//请求数据
	
}


//查询向后台请求部门信息
function requestDepartment()
{	var url="getAllPrisonArea.do";//分口地址


	var data={};
	var object={};
	data=YuXi.util.get(url,null,function(data){
		object=data.object;
		 var html="<option  value=1>监狱</option>";
			 $(".reDepartment").append(html);
		//用data循环添加部门信息	
		for(var i=0;i<object.length;i++)
		{
			 var html="<option  value="+object[i].id+">"+object[i].name+"</option>";
			 $(".reDepartment").append(html);
		}
		
	},function(){});//请求数据
	
}




//向后台请求分类信息
function requestSort()
{	//数据模拟

	
	
	var url="getAllInfomationSort.do";//分类地址
	var data={};
	var object={};
	data=YuXi.util.get(url,"null",function(data){
		object=data.object;
		//用data循环添加分类信息
		for(var i=0;i<object.length;i++)
		{
			var html="<option  value="+object[i].id+" >"+object[i].name+"</option>";
			$(".sort").append(html);
		}
	},function(){
		
	});//请求数据
	
}

//向后台请求渠道信息
function requestSource()
{	
	
	var url="getAllInfomationSource.do";//渠道地址
	var data={};
	var object={};
	data=YuXi.util.getAsynCache(url,"null",function(data){
		object=data.object;
		$("#s0").html("");
		xxx(object,"#mut");
		
	},function(){});//请求数据
	
}
//查询向后台请求分口信息
function requestPort()
{	var url="getAllInformationPort.do";//分口地址
	var data={};
	var object={};
	data=YuXi.util.getAsynCache(url,null,function(data){
		object=data.object;
		//用data循环添加分口信息	
		$("#s0").html("");
		xxx(object,"#fenk");
	},function(){});//请求数据
	
}

function xxx(object,className)
{

	var a=[];
	var flag=0;
	
	var flaga={};
	
function treeMenu(a){
    this.tree=a||[];
    this.groups={};
};
treeMenu.prototype={
    init:function(superId){
    
        this.group();
        return this.getDom(this.groups[superId]);
    },
    group:function(){
    	
        for(var i=0;i<this.tree.length;i++){
            if(this.groups[this.tree[i].superId]){
                this.groups[this.tree[i].superId].push(this.tree[i]);
            }else{
                this.groups[this.tree[i].superId]=[];
                this.groups[this.tree[i].superId].push(this.tree[i]);
            }
        }

    },

    getDom:function(a){
        if(!a){return ''}

       flag=0;
        var html="";
    	if(a[0].superId==0)
    	{
    		for(var i=0;i<a.length;i++)
    		{
    			if(className=="#fenk")
    			{
    				html='<optgroup id="s'+a[i].id+'" label="'+a[i].portName+'"><option data-super='+a[i].superId+' value="'+a[i].id+'">&nbsp;&nbsp;'+a[i].portName+'</option></optgroup>';
    			}
    			else
    			{
    				html='<optgroup id="s'+a[i].id+'" label="'+a[i].name+'"><option data-super='+a[i].superId+' value="'+a[i].id+'">&nbsp;&nbsp;'+a[i].name+'</option></optgroup>';
    			
    			}
    			$("#s0").append(html);
    			
    		}
    		flag=1;
    	}
    	
    	if(flag==0)
    	{
    		
    			
    			var length=a.length;

    			for(var i=0;i<length;i++)
    			{
    			
    			
    				var xx=a[i].id;
    				var asuperid=a[i].superId;
    				var aname="";
    				if(className=="#fenk")
    				{
    					aname=a[i].portName;
    				}
    				else
    				{
    					aname=a[i].name;
    				}
    				var biao=0;
    				x=1;
    				var flagx=space(asuperid,object);
    				
    				var spacea="";//添加空格
    				for(var m=0;m<=flagx;m++)
    				{
    					spacea=spacea+"&nbsp;";
    				}
    				
    				for(var j=0;j<object.length;j++)
    				{

    					if(xx==object[j].superId)
    					{
    						html='<optgroup id="s'+xx+'" label="&nbsp;'+spacea+aname+'"><option data-super='+asuperid+' value="'+xx+'">&nbsp;'+spacea+aname+'</option></optgroup>';
    						
    						$("#s"+asuperid).append(html);
    						biao=1;
    						break;
    					}

    				}

    				if(biao==0)
    				{
    					html='<option data-super='+asuperid+' value="'+xx+'">&nbsp;'+spacea+aname+'</option>';
    					
    				    $("#s"+asuperid).append(html);
    				}
    					
    			}
    		
    	}
    	 
        for(var i=0;i<a.length;i++){
        	if(className=="#fenk")
        	{
        		 flaga={id:a[i].id,name:a[i].portName,superid:a[i].superid};
        	}
       		else
       		{
       			flaga={id:a[i].id,name:a[i].name,superid:a[i].superid};
       		}
        	
           this.getDom(this.groups[a[i].id]);

        };

        /*html+='</optgroup>\n';*/

       /* $("#"+id).append(html);*/
        return html;
    }
};
	var html=new treeMenu(object).init(0);
	var hh=$("#s0").html();
	var html="";
	if(className=="#fenk")
	{
		html='<option value=null selected="selected">分口(所有)</option>';
	}
	else
	{
		html='<option value=null selected="selected">来源渠道(所有)</option>';
	}
	$(className).html(html);
	$(className).append(hh);
}
var x=1;	//向后台请求渠道信息
function space(superid,object)
{

	if(superid==0)
	{

		return 0;
	}
	for(var i=0;i<object.length;i++)
	{
		if(object[i].id==superid)
		{
			
			x=space(object[i].superId,object);
			
		}
	}
	return x+1;

}
function requestClassification() 
{

	var url = "getAllInformationClassification.do"; //分级地址
	var data = {};
	var object = {};
	data = YuXi.util.get(url, "null", function(data) {
		object = data.object;
		for (var i = 0; i < object.length; i++) {
			var html = "<option  value=" + object[i].id + " >" + object[i].name + "</option>";
			$(".reSearchpes").append(html);
		}
	}, function() {

	}); //请求数据
}
 function requestSort()
 {	

		var url="getAllInfomationSort.do";//分类地址
		var data={};
		var object={};
		data=YuXi.util.get(url,"null",function(data){
			object=data.object;
			//用data循环添加分类信息
			for(var i=0;i<object.length;i++)
			{
				var html="<option  value="+object[i].id+" >"+object[i].name+"</option>";
				$(".reSearchsort").append(html);
			}
		},function(){
			
		});//请求数据
		
}
	$("#mut").change(function(){
		try{
			
			if($("#mut").select2('val').length>1)
			{
				$("#mut option[value='null']").remove();
				var html='<option value="null">来源渠道(所有)</option>';
				$("#mut").prepend(html);
			}
		}
		catch(e){

		}

	})
	
});
